#include "Lines.h"

void Lines::Init()
{ 

	for( i=0;i<SINSIZE;i++ )
		sintable[i] = (int)(sin( 2.0f * 3.14159 * (float)i / SINSIZE) *128.0f)+128;
	return; 
}

void Lines::RenderFrame(long double curTime)
{
	static long double startTime=0, lastTime=0;
	int i;
	int x,y,z;
	float scale = 1.0f/50.0f;
	static long double s_x=0, s_y=0, s_z=0;
	static int i_x=0, i_y=0, i_z=0;
	double i_xf, i_yf, i_zf;

	curTime *= 1000;

	if( startTime == 0 )
		startTime = curTime;

	curTime = curTime-startTime;

	glPushMatrix();

	x = s_x;
	y = s_y;
	z = s_z;
	i_xf = i_x;
	i_yf = i_y;
	i_zf = i_z;

	glColor4f(0.3 + (0.5 * fabs(sin(curTime/2800))),0.2 + (0.5 * fabs(sin(curTime/1900))),0.4 + (0.5 * cos(curTime/2400)), .3f);
		glBegin(GL_TRIANGLE_STRIP);
		for( i=0;i<2000;i++ )
		{
				glVertex3f(scale*sintable[x]-4, (scale*sintable[y]-4), (scale*sintable[z]-6) );
			x= (x+(int)i_xf+SINSIZE)%SINSIZE;
			y= (y+(int)i_yf+SINSIZE)%SINSIZE;
			z= (z+(int)i_zf+SINSIZE)%SINSIZE;
			i_xf = (i_xf+0.11f);
			i_yf = (i_yf+0.12f);
			i_zf = (i_zf+0.13f);
		}
		glEnd();

		s_x+=0.02*(curTime-lastTime);
		s_y+=0.03*(curTime-lastTime);
		s_z+=0.02*(curTime-lastTime);

		s_x = fmodf(s_x, (float)SINSIZE);
		s_y = fmodf(s_y, (float)SINSIZE);
		s_z = fmodf(s_z, (float)SINSIZE);

	glPopMatrix();

		glColor4f(0.4 + (0.4 * sin(curTime/2800)),0.4 + (0.4 * sin(curTime/1900)),0.4 + (0.4 * fabs(cos(curTime/2400))), 0.3f );
		glBegin(GL_LINES);
		for( i=0;i<2000;i++ )
		{
				glVertex3f(scale*sintable[x]-4, (scale*sintable[y]-4), (scale*sintable[z]-6) );
			x= (x+(int)i_xf+SINSIZE)%SINSIZE;
			y= (y+(int)i_yf+SINSIZE)%SINSIZE;
			z= (z+(int)i_zf+SINSIZE)%SINSIZE;
			i_xf = (i_xf+0.11f);
			i_yf = (i_yf+0.12f);
			i_zf = (i_zf+0.13f);
		}
		glEnd();

		s_x+=0.02*(curTime-lastTime);
		s_y+=0.03*(curTime-lastTime);
		s_z+=0.02*(curTime-lastTime);

		s_x = fmodf(s_x, (float)SINSIZE);
		s_y = fmodf(s_y, (float)SINSIZE);
		s_z = fmodf(s_z, (float)SINSIZE);

  glPopMatrix();

	lastTime = curTime;
}

